/**
 * 
 */
package com.pmsco.pms.business;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.pmsco.pms.business.dto.UserMainInfoRequestDTO;
import com.pmsco.pms.business.dto.UserMainInfoReturnDTO;
import com.pmsco.pms.core.domain.PmsUser;
import com.pmsco.pms.services.impl.PmsUserServiceImpl;
import com.pmsco.pms.services.interfaces.PmsUserService;

/**
 * @author Long Tran
 *
 */
public class UserBusiness {
	private static final Logger logger = LoggerFactory.getLogger(UserBusiness.class);
	private PmsUserService pmsUserService = new PmsUserServiceImpl();
	
	public UserMainInfoReturnDTO loadAccountInfo(UserMainInfoRequestDTO userMainInfoRequestDTO) {
		logger.info("Start loadAccountInfo");
		UserMainInfoReturnDTO userMainInfoReturnDTO = new UserMainInfoReturnDTO();
		
		PmsUser pmsUser = pmsUserService.loadPmsUserByName(userMainInfoRequestDTO.getUserName());
		userMainInfoReturnDTO.setPmsUser(pmsUser);
		
		logger.info("End loadAccountInfo");
		return userMainInfoReturnDTO;
	}
	
	public UserMainInfoReturnDTO saveAccountInfo(UserMainInfoRequestDTO userMainInfoRequestDTO) {
		logger.info("Start saveAccountInfo");
		UserMainInfoReturnDTO userMainInfoReturnDTO = new UserMainInfoReturnDTO();
		
		PmsUser pmsUser = pmsUserService.loadPmsUserByName(userMainInfoRequestDTO.getUserName());
		pmsUser.setLastName(userMainInfoRequestDTO.getLastName());
		pmsUser.setMidName(userMainInfoRequestDTO.getMidName());
		pmsUser.setFirstName(userMainInfoRequestDTO.getFirstName());
		pmsUser.setIdNumber(userMainInfoRequestDTO.getIdNumber());
		pmsUser.setDob(userMainInfoRequestDTO.getDob());
		pmsUser.setCellPhone(userMainInfoRequestDTO.getCellPhone());
		pmsUser.setHomePhone(userMainInfoRequestDTO.getHomePhone());
		pmsUser.setHomeAddr(userMainInfoRequestDTO.getHomeAddr());
		pmsUserService.saveOrUpdatePmsUser(pmsUser);	
		
		logger.info("End saveAccountInfo");
		return userMainInfoReturnDTO;
	}
}
